"""
Copyright (c) 2023 - present SKbioinfo
"""
from flask_restful import Resource
from flask import jsonify
from apps.API.utils.log_helper import lg
from flask_jwt_extended import jwt_required
import os,psutil
"""URL:/api/disk/monitor"""
class interfaceDiskMonitor(Resource):
    @jwt_required()
    def get(self):
        try:
            current_dir = os.getcwd()
            disk_storage = {}
            usage = psutil.disk_usage(current_dir)
            disk_storage["usage_total"] = str(f"{usage.total / (1024**3):.2f} GB")
            disk_storage["usage_used"] = str(f"{usage.used / (1024**3):.2f} GB")
            disk_storage["usage_free"] = str(f"{usage.free / (1024**3):.2f} GB")
            disk_storage["usage_percent"] = str(f"{usage.percent}%")
            return jsonify(disk_storage)
        except Exception as e:
            response=jsonify([])
            response.status=404
            return response